package com.mobiftpcms.model;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import com.mobiftpcms.model.BaseObject;
import com.mobiftpcms.model.User;
import com.mobiftpcms.model.UserTaskParam;

@Entity
@Table(name = "user_task")
@Searchable
public class UserTask extends BaseObject implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7830260869090052195L;

	private Long id;
	
	private String taskName;
	
	private Set<User> users;
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "task_name", nullable = false, length = 100)
    @SearchableProperty
	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "userTasks")
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public boolean equals(Object o) {
		if(o != null) {
			if(o instanceof UserTask) {
				UserTask t = (UserTask) o;
				return t.getId().equals(getId());
			}
		}
		return false;
	}
	
	public int hashCode() {
		return id.intValue();
	}
	
	public String toString() {
		return getTaskName();
	}
	
	
}
